namespace ghost {
	/**场景业务逻辑基类，编写所有场景业务均有的逻辑*/
	export class SceneBase implements IResource, map2D.ISceneLogicBase{
		protected _disposed:boolean;
		protected _inited:boolean;
		public _areaGridW:number;
        public _areaGridH:number;
        public _posGridW:number;
        public _posGridH:number;
		public sceneMgr:map2D.SceneManagerBase;
		public constructor(scene:map2D.SceneManagerBase) {
			this.sceneMgr = scene;
		}
		/**场景初始化*/
		public init():boolean
		{
			let s= this;
			if(s._inited)return false;
			s._inited = true;
			return true;
		}
		public get inited():boolean
		{
			return this._inited;
		}
		public start():void
		{

		}
		public netReady():void
		{

		}
		public configSet(sceneCfg:any):void
		{
			let s = this;
			s._areaGridW = sceneCfg.areaGridW;
            s._areaGridH = sceneCfg.areaGridH;
            s._posGridW = s.sceneMgr.sceneCfg.posGridW?s.sceneMgr.sceneCfg.posGridW:s.sceneMgr.gridSize;
            s._posGridH = s.sceneMgr.sceneCfg.posGridH?s.sceneMgr.sceneCfg.posGridH:s.sceneMgr.gridSize;         
			
		}
		public inPos(r:GameRole):void
        {            
			let s= this;
            r.col = Math.floor(r.absX / s._posGridW);
            r.row = Math.floor(r.absY / s._posGridH);
			let state:number = s.sceneMgr.barrier.barrierGridState(r.col,r.row, map2D.Barrier.STEP_PASS);
            let flag:boolean = true;//r._gameRoleSubType != GameRoleSubType.STATIC;
            r.inBarrierPos = flag && state == 0;
            r.inAirPos = flag && (state & map2D.Barrier.AIR) > 0;
        }        
        public outPos(r:GameRole):void
        {            
            r.col = r.row = NaN;			
        } 
		public inArea(r:GameRole):void
		{
            let col:number,row:number;
            col = r.absX / this.sceneMgr.mapAreaSize | 0;
            row = r.absY / this.sceneMgr.mapAreaSize | 0;
            if(col == r.areaCol && row == r.areaRow)return;
			r.areaCol = col;
			r.areaRow = row;
            r.areaKey = r.areaRow + "_" + r.areaCol;
		}		
		public outArea(r:GameRole, areaCol:number, areaRow:number):void
		{
			r.areaCol = NaN;
			r.areaRow = NaN;
            r.areaKey = null;
		}      
		public get disposed():boolean
		{
			return this._disposed;
		}
		public dispose():void
		{
			let s= this;
			if(s._disposed)return;
			s._disposed = true;
		}

		public loop(t:number):void
		{

		}
		public roleDead(r:GameRole, atkData:OwnerData=null, buffData:ghost.IBuffData=null):void
		{
		
		}
		
	}
}